﻿@model ConferenceQuizModel
@{
	ViewBag.Title = Resources.ConferenceQuiz + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.QuizName：<input id="selQuizName" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="searchData();">@Resources.Search</a>&nbsp;&nbsp;
		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceQuiz, RoleType.浏览))
		{
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-add" onclick="addData();" plain="true">@Resources.Create</a>
		}
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-export" onclick="exportData();" plain="true">@Resources.Export</a>
	</div>
	<form id="frmExport" method="post" target="iframeDownload" action="@Url.Action(nameof(ConferenceQuizController.Export))">
		@Html.AntiForgeryToken()
		<input type="hidden" id="hdnIds" name="quizId" />
		<input type="hidden" id="hdnConferenceId" name="conferenceId" />
	</form>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section bodyParts {
<div id="detailWindow" class="easyui-window"
	title="@Resources.ConferenceQuiz" data-options="closed:true,minimizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01"></h3>
			<form id="frmDetail" method="post">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.QuizName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="hidden" id="hidID" name="Id" />
							<input type="hidden" id="hidConferenceId" name="ConferenceId" />
							<input id="txtQuizName" name="QuizName" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']" />
						</td>
						<td style="text-align: right;" class="w1 c1"></td>
						<td style="text-align: left;" class="w2 c2"></td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Status：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="ddlStatus" name="Status" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true">
								<option value="@ConstValues.Status.正常">@Resources.Normal</option>
								<option value="@ConstValues.Status.暂停">@Resources.Pause</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.Sort：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtSort" name="Sort" class="easyui-numberbox" style="height:27px; width:300px;" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Remark：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtRemark" name="Remark" class="easyui-textbox" style="height:50px; width:892px;" data-options="multiline:true, validType:['length[1,1000]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnWindowType" />
				<input type="button" class="gbtn" onclick="saveData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#detailWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
<div id="questionWindow" class="easyui-window"
	title="@Resources.Question" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="questionWindowTitle" class="tit01" style="text-align:left;"><a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-add" style="background:#919295;color:#000;border:none;margin-left:5px;" onclick="addQuestion();">@Resources.Create@Resources.Question</a></h3>
			<form id="frmQuestion" method="post">
				@Html.AntiForgeryToken()
				<table id="questionDG"></table>
				<table width="100%" height="100%" id="tblQuestion" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.QuestionName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="hidden" id="hidQuestionConferenceId" name="ConferenceId" />
							<input type="hidden" id="hidQuestionQuizId" name="QuizId" />
							<input type="hidden" id="hidQuestionId" name="QuestionId" />
							<input id="txtQuestionName" name="QuestionName" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']" />
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.QuestionType：</td>
						<td style="text-align: left;" class="w2 c2">
							<select id="ddlQuestionType" name="QuestionType" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.QuestionType.单选题">@Resources.SingleChoice</option>
								<option value="@ConstValues.QuestionType.多选题">@Resources.MultipleChoice</option>
								<option value="@ConstValues.QuestionType.填空题">@Resources.FillBlank</option>
							</select>
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Status：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="ddlQuestionStatus" name="Status" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true">
								<option value="@ConstValues.Status.正常">@Resources.Normal</option>
								<option value="@ConstValues.Status.暂停">@Resources.Pause</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.Sort：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtQuestionSort" name="Sort" class="easyui-numberbox" style="height:27px; width:300px;" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Remark：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtQuestionRemark" name="Remark" class="easyui-textbox" style="height:50px; width:892px;" data-options="multiline:true, validType:['length[1,1000]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnQuestionType" value="add" />
				<input type="button" class="gbtn" onclick="saveQuestion();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#questionWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
<div id="answerWindow" class="easyui-window"
	title="@Resources.Answer" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="answerWindowTitle" class="tit01" style="text-align:left;"><a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-add" style="background:#919295;color:#000;border:none;margin-left:5px;" onclick="addAnswer();">@Resources.Create@Resources.Answer</a></h3>
			<form id="frmAnswer" method="post">
				@Html.AntiForgeryToken()
				<table id="answerDG"></table>
				<table width="100%" height="100%" id="tblAnswer" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Answer：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="hidden" id="hidAnswerConferenceId" name="ConferenceId" />
							<input type="hidden" id="hidAnswerQuizId" name="QuizId" />
							<input type="hidden" id="hidAnswerQuestionId" name="QuestionId" />
							<input type="hidden" id="hidAnswerId" name="AnswerId" />
							<input id="txtAnswer" name="Answer" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']" />
						</td>
						<td style="text-align: right;" class="w1 c1">@*@Resources.IsCorrect：*@</td>
						<td style="text-align: left;" class="w2 c2">
							@*<input type="checkbox" id="chkIsCorrect" name="IsCorrect" style="height:25px; vertical-align:top;" />*@
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Status：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="ddlAnswerStatus" name="Status" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.Status.正常">@Resources.Normal</option>
								<option value="@ConstValues.Status.暂停">@Resources.Pause</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.Sort：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtAnswerSort" name="Sort" class="easyui-numberbox" style="height:27px; width:300px;" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Remark：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtAnswerRemark" name="Remark" class="easyui-textbox" style="height:50px; width:892px;" data-options="multiline:true, validType:['length[1,1000]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnAnswerType" value="add" />
				<input type="button" class="gbtn" onclick="saveAnswer();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#answerWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceQuiz");

	$(function () {
		$("#hidConferenceId").val("@Model.ConferenceId");

		$("#selQuizName").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceQuizController.GetData),
					nameof(ConferenceQuizController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
			method: "get",
			checkOnSelect: false,
			singleSelect: true,
			fitColumns: true,
			width: $(window).width() - 285,
			height: $(window).height() - 158,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100,
			pageList: [100, 200, 300, 400, 500],
			columns: [[
				{ field: "id", hidden: true },
				{ field: "chk", align: "center", checkbox: true },
				@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceQuiz, RoleType.修改) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceQuiz, RoleType.删除))
				{
					<text>
					{
						field: "operate", title: "@Resources.Operate", align: "center", width: 150,
						formatter: function(value, rec) {
							var strInfo = "";
							var tmp = rec.quizName == null ? "" : rec.quizName.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
							@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceQuiz, RoleType.修改))
							{
								<text>
								strInfo += "<a href='#' style='color:#FF8C00;font-weight:bold;text-decoration:underline;' onclick='openQuestion(\""
									+ rec.id + "\")'>@Resources.Question</a>";
								strInfo += "&nbsp;|&nbsp;";
								strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editData(\""
									+ rec.id + "\")'>@Resources.Modify</a>";
								</text>
							}
							@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceQuiz, RoleType.删除))
							{
								<text>
								if (strInfo != "") {
									strInfo += "&nbsp;|&nbsp;";
								}
								strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteData(\""
									+ rec.id + "\",\"" +tmp + "\")'>@Resources.Delete</a>";
								</text>
							}
							return strInfo;
						}
					},
					</text>
				}
				{ field: "quizName", title: "@Resources.QuizName", align: "center", sortable: true, width: 200 },
				{ field: "sort", title: "@Resources.Sort", align: "center", sortable: true, width: 100 },
				{
					field: "status", title: "@Resources.Status", align: "center", sortable: true, width: 100,
					formatter: function(value, rec) {
						if(value=="@ConstValues.Status.正常"){
							return "@Resources.Normal"
						}else{
							return "@Resources.Pause"
						}
					}
				},
				{ field: "remark", title: "@Resources.Remark", align: "center", sortable: true, width: 200 },
				{ field: "creator", title: "@Resources.Creator", align: "center", sortable: true, width: 100 },
				{ field: "createIP", title: "@Resources.CreateIP", align: "center", sortable: true, width: 150 },
				{ field: "createDate", title: "@Resources.CreateDate", align: "center", sortable: true, width: 150 },
			]],
			onBeforeLoad: function(param) {
				param.conferenceId = $("#hidConferenceId").val();
				param.random = Math.random();
			},
			onLoadSuccess: function(data) {
				var exportIdList = $("#hdnIds").val();
				if (data.rows.length > 0) {
					var exportIdArray = exportIdList.split(',');
					for (var rowIndex = 0; rowIndex < data.rows.length; rowIndex++) {
						for (var index = 0; index < exportIdArray.length; index++) {
							if (data.rows[rowIndex].id == exportIdArray[index]) {
								$("input[type='checkbox']").eq(rowIndex + 1).prop("checked", true);
								break;
							}
						}
					}
				}
			},
			onCheck: function (rowIndex, rowData) {
				var exportIdList = $("#hdnIds").val();
				var strId = rowData.id.toString();
				if (exportIdList == "") {
					$("#hdnIds").val(strId);
				} else {
					var exportIdArray = exportIdList.split(',');
					var newArray = exportIdArray.concat(strId);
					$("#hdnIds").val(newArray.join());
				}
			},
			onUncheck: function (rowIndex, rowData) {
				var exportIdList = $("#hdnIds").val();
				var exportIdArray = exportIdList.split(',');
				var strId = rowData.id.toString();
				exportIdArray.remove(strId);
				$("#hdnIds").val(exportIdArray.join());
			},
			onCheckAll: function (rows) {
				var exportIdList = $("#hdnIds").val();
				if (exportIdList == "") {
					var newArray = new Array();
					for (var index = 0; index < rows.length; index++) {
						var strId = rows[index].id.toString();
						newArray = newArray.concat(strId);
					}
					$("#hdnIds").val(newArray.join());
				} else {
					var exportIdArray = exportIdList.split(',');
					var newArray = exportIdArray;
					for (var index = 0; index < rows.length; index++) {
						var strId = rows[index].id.toString();
						if (newArray.indexOf(strId) < 0) {
							newArray = newArray.concat(strId);
						}
					}
					$("#hdnIds").val(newArray.join());
				}
			},
			onUncheckAll: function (rows) {
				var exportIdList = $("#hdnIds").val();
				var exportIdArray = exportIdList.split(',');
				for (var index = 0; index < rows.length; index++) {
					var strId = rows[index].id.toString();
					exportIdArray.remove(strId);
				}
				$("#hdnIds").val(exportIdArray.join());
			},
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 158
			});
		});

		$("#detailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});

		$("#questionWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});

		$("#answerWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});
	});

	function searchData() {
		$("#hdnIds").val("");
		$("#dataGrid").datagrid("load", {
			SelQuizName: $("#selQuizName").textbox("getValue")
		});
	}

	function exportData() {
		var exportIdList = $("#hdnIds").val();

		if (exportIdList == "") {
			$.messager.alert("@Resources.Export", "@Resources.MsgRecordMust", "warning");
			return;
		}

		$("#hdnConferenceId").val("@Model.ConferenceId");
		$("#frmExport").submit();
	}

	function addData() {
		$("#hdnWindowType").val("add");
		$("#detailWindowTitle").text("@Resources.Create");
		$("#hidID").val("");
		$("#txtQuizName").textbox("setValue", "");
		$("#ddlStatus").combobox("setValue", "@ConstValues.Status.正常");
		$("#txtSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtRemark").textbox("setValue", "");
		$("#detailWindow").window("open");
	}

	function editData(id) {
		var url = "@Url.Action(nameof(ConferenceQuizController.GetEditData),
				nameof(ConferenceQuizController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#dataGrid").datagrid("reload");
			} else {
				$("#hdnWindowType").val("edit");
				$("#detailWindowTitle").text("@Resources.Modify");
				$("#hidID").val(id);
				$("#txtQuizName").textbox("setValue", data.data.quizName);
				$("#ddlStatus").combobox("setValue", data.data.status);
				$("#txtSort").numberbox("setValue", data.data.sort);
				$("#txtRemark").textbox("setValue", data.data.remark);
				$("#detailWindow").window("open");
			}
		});
	}

	function deleteData(id, name) {
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, name);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidID").val(id);
				$.post("@Url.Action(nameof(ConferenceQuizController.Delete),
						nameof(ConferenceQuizController).GetControllerName(),
					new { ConferenceId = Model.ConferenceId })",
					$("#frmDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	}

	function saveData() {
		var isValid = $("#frmDetail").form("validate");

		if (isValid) {
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});
					switch ($("#hdnWindowType").val())
					{
						case "add":
							$.post("@Url.Action(nameof(ConferenceQuizController.Create),
									nameof(ConferenceQuizController).GetControllerName())",
								$("#frmDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#detailWindow").window("close");
										$("#dataGrid").datagrid("reload");
									}
								}
							);
							break;
						case "edit":
							$.post("@Url.Action(nameof(ConferenceQuizController.Modify),
									nameof(ConferenceQuizController).GetControllerName())",
								$("#frmDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#detailWindow").window("close");
										$("#dataGrid").datagrid("reload");
									}
								}
							);
							break;
					}
				}
			});
		}
	}

	function openQuestion(id) {
		$("#hidQuestionConferenceId").val("@Model.ConferenceId");
		$("#hidQuestionQuizId").val(id);

		$("#questionDG").datagrid({
			url: "@Url.Action(nameof(ConferenceQuizController.GetQuestionData),
					nameof(ConferenceQuizController).GetControllerName())",
			method: "get",
			fitColumns: true,
			height: 278,
			nowrap: false,
			striped: true,
			columns: [[
				{
					field: "operate", title: "@Resources.Operate", align: "center", width: 100,
					formatter: function(value, rec) {
						var tmp = rec.questionName == null ? "" : rec.questionName.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
						var strInfo = "";
						strInfo += "<a href='#' style='color:#FF8C00;font-weight:bold;text-decoration:underline;' onclick='openAnswer(\""
							+ rec.id + "\",\"" + id + "\")'>@Resources.Answer</a>";
						strInfo += "&nbsp;|&nbsp;";
						strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editQuestion(\""
							+ rec.id + "\")'>@Resources.Modify</a>";
						strInfo += "&nbsp;|&nbsp;";
						strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteQuestion(\""
							+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
						return strInfo;
					}
				},
				{ field: "questionName", title: "@Resources.QuestionName", align: "center", width: 300 },
				{ field: "questionType", title: "@Resources.QuestionType", align: "center", width: 100 },
			]],
			onBeforeLoad: function(param) {
				param.quizId = id;
				param.random = Math.random();
			},
			onLoadSuccess: function (data) {
				$(this).datagrid("autoMergeCells", ["questionType"]);
			}
		});

		$("#hdnQuestionType").val("add");
		$("#hidQuestionId").val("");
		$("#txtQuestionName").textbox("setValue", "");
		$("#ddlQuestionType").combobox("setValue", "");
		$("#ddlQuestionStatus").combobox("setValue", "@ConstValues.Status.正常");
		$("#txtQuestionSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtQuestionRemark").textbox("setValue", "");
		$("#questionWindow").window("open");
	}

	function addQuestion() {
		$("#hdnQuestionType").val("add");
		$("#hidQuestionId").val("");
		$("#txtQuestionName").textbox("setValue", "");
		$("#ddlQuestionType").combobox("setValue", "");
		$("#ddlQuestionStatus").combobox("setValue", "@ConstValues.Status.正常");
		$("#txtQuestionSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtQuestionRemark").textbox("setValue", "");
		$("#questionWindow").window("open");
	}

	function editQuestion(id) {
		var url = "@Url.Action(nameof(ConferenceQuizController.GetEditQuestionData),
				nameof(ConferenceQuizController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#questionDG").datagrid("reload");
			} else {
				$("#hdnQuestionType").val("edit");
				$("#hidQuestionId").val(id);
				$("#txtQuestionName").textbox("setValue", data.data.questionName);
				$("#ddlQuestionType").combobox("setValue", data.data.questionType);
				$("#ddlQuestionStatus").combobox("setValue", data.data.status);
				$("#txtQuestionSort").numberbox("setValue", data.data.sort);
				$("#txtQuestionRemark").textbox("setValue", data.data.remark);
				$("#questionWindow").window("open");
			}
		});
	}

	function deleteQuestion(id, name) {
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, name);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidQuestionId").val(id);
				$.post("@Url.Action(nameof(ConferenceQuizController.DeleteQuestion),
						nameof(ConferenceQuizController).GetControllerName(),
					new { ConferenceId = Model.ConferenceId })",
					$("#frmQuestion").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#questionDG").datagrid("reload");
						}
					}
				);
			}
		});
	}

	function saveQuestion() {
		var isValid = $("#frmQuestion").form("validate");

		if (isValid) {
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});
					switch ($("#hdnQuestionType").val())
					{
						case "add":
							$.post("@Url.Action(nameof(ConferenceQuizController.CreateQuestion),
									nameof(ConferenceQuizController).GetControllerName())",
								$("#frmQuestion").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#questionDG").datagrid("reload");
									}
								}
							);
							break;
						case "edit":
							$.post("@Url.Action(nameof(ConferenceQuizController.ModifyQuestion),
									nameof(ConferenceQuizController).GetControllerName())",
								$("#frmQuestion").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#questionDG").datagrid("reload");
									}
								}
							);
							break;
					}
				}
			});
		}
	}

	function openAnswer(id, quizId) {
		$("#hidAnswerConferenceId").val("@Model.ConferenceId");
		$("#hidAnswerQuizId").val(quizId);
		$("#hidAnswerQuestionId").val(id);

		$("#answerDG").datagrid({
			url: "@Url.Action(nameof(ConferenceQuizController.GetAnswerData),
					nameof(ConferenceQuizController).GetControllerName())",
			method: "get",
			fitColumns: true,
			height: 278,
			nowrap: false,
			striped: true,
			columns: [[
				{
					field: "operate", title: "@Resources.Operate", align: "center", width: 100,
					formatter: function(value, rec) {
						var tmp = rec.answer == null ? "" : rec.answer.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
						var strInfo = "";
						strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editAnswer(\""
							+ rec.id + "\")'>@Resources.Modify</a>";
						strInfo += "&nbsp;|&nbsp;";
						strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteAnswer(\""
							+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
						return strInfo;
					}
				},
				{ field: "answer", title: "@Resources.Answer", align: "center", width: 300 },
			]],
			onBeforeLoad: function(param) {
				param.questionId = id;
				param.random = Math.random();
			}
		});

		$("#hdnAnswerType").val("add");
		$("#hidAnswerId").val("");
		$("#txtAnswer").textbox("setValue", "");
		$("#ddlAnswerStatus").combobox("setValue", "@ConstValues.Status.正常");
		$("#txtAnswerSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtAnswerRemark").textbox("setValue", "");
		$("#answerWindow").window("open");
	}

	function addAnswer() {
		$("#hdnAnswerType").val("add");
		$("#hidAnswerId").val("");
		$("#txtAnswer").textbox("setValue", "");
		$("#ddlAnswerStatus").combobox("setValue", "@ConstValues.Status.正常");
		$("#txtAnswerSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtAnswerRemark").textbox("setValue", "");
		$("#answerWindow").window("open");
	}

	function editAnswer(id) {
		var url = "@Url.Action(nameof(ConferenceQuizController.GetEditAnswerData),
				nameof(ConferenceQuizController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#answerDG").datagrid("reload");
			} else {
				$("#hdnAnswerType").val("edit");
				$("#hidAnswerId").val(id);
				$("#txtAnswer").textbox("setValue", data.data.answer);
				$("#ddlAnswerStatus").combobox("setValue", data.data.status);
				$("#txtAnswerSort").numberbox("setValue", data.data.sort);
				$("#txtAnswerRemark").textbox("setValue", data.data.remark);
				$("#answerWindow").window("open");
			}
		});
	}

	function deleteAnswer(id, name) {
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, name);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidAnswerId").val(id);
				$.post("@Url.Action(nameof(ConferenceQuizController.DeleteAnswer),
						nameof(ConferenceQuizController).GetControllerName(),
					new { ConferenceId = Model.ConferenceId })",
					$("#frmAnswer").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#answerDG").datagrid("reload");
						}
					}
				);
			}
		});
	}

	function saveAnswer() {
		var isValid = $("#frmAnswer").form("validate");

		if (isValid) {
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});
					switch ($("#hdnAnswerType").val())
					{
						case "add":
							$.post("@Url.Action(nameof(ConferenceQuizController.CreateAnswer),
									nameof(ConferenceQuizController).GetControllerName())",
								$("#frmAnswer").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#answerDG").datagrid("reload");
									}
								}
							);
							break;
						case "edit":
							$.post("@Url.Action(nameof(ConferenceQuizController.ModifyAnswer),
									nameof(ConferenceQuizController).GetControllerName())",
								$("#frmAnswer").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#answerDG").datagrid("reload");
									}
								}
							);
							break;
					}
				}
			});
		}
	}
</script>
}